<?php
class xl_users{
     function read(){
        global $dbh;
		$sql='SELECT * FROM users ORDER BY id DESC';
		$sth=$dbh->prepare($sql);
		$sth->execute();
		return $sth->fetchAll();	 
    }
    function read_id($id){
        global $dbh;
        $sql='SELECT * FROM users WHERE id=:id LIMIT 0,1';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return  $sth->fetch(PDO::FETCH_ASSOC);
    }
    function delete_all($id){
        global $dbh;
        $sql='SELECT * FROM users WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth->fetch(PDO::FETCH_ASSOC);
    }
    function delete($id){
        global $dbh;
        $sql='DELETE FROM users WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth;
    }
    function update_status($id){
        global $dbh;
        $sql='UPDATE users SET status=1-status WHERE id=:id';
        $sth=$dbh->prepare($sql);
        $sth->execute(array(':id'=>$id));
        return $sth;
    }
}